
var initShopInfoBean;
var getShopInfoBeanFromOpenPage = function(){
	var shopinfoBean = {};
	shopinfoBean.id = jQuery('#idEditor').val();
	
	shopinfoBean.name = jQuery('#nameEditor').val();
	if(!shopinfoBean.name){
		$.ligerDialog.error("请输入商户名!");
		return null;
	}	shopinfoBean.masterName = jQuery('#masterNameEditor').val();
	if(!shopinfoBean.masterName){
		$.ligerDialog.error("请输入店主姓名!");
		return null;
	}	shopinfoBean.masterCard = jQuery('#masterCardEditor').val();
	if(!shopinfoBean.masterCard){
		$.ligerDialog.error("请输入店主身份证!");
		return null;
	}	shopinfoBean.email = jQuery('#emailEditor').val();
	if(!shopinfoBean.email){
		$.ligerDialog.error("请输入邮箱(帐号)!");
		return null;
	}	shopinfoBean.phone = jQuery('#phoneEditor').val();
	if(!shopinfoBean.phone){
		$.ligerDialog.error("请输入商户电话!");
		return null;
	}	shopinfoBean.address = jQuery('#addressEditor').val();
	if(!shopinfoBean.address){
		$.ligerDialog.error("请输入地址!");
		return null;
	}	shopinfoBean.registerTime = jQuery('#registerTimeEditor').val();
	if(!shopinfoBean.registerTime){
		$.ligerDialog.error("请输入注册时间!");
		return null;
	}else{
		shopinfoBean.registerTime = new Date(Date.parse((shopinfoBean.registerTime+':00').replace(/-/g,   "/")));
	}
	shopinfoBean.state = jQuery('#stateEditor').val();
	if(!shopinfoBean.state){
		$.ligerDialog.error("请输入状态!");
		return null;
	}	shopinfoBean.passwd = jQuery('#passwdEditor').val();
	if(!shopinfoBean.passwd){
		$.ligerDialog.error("请输入密码!");
		return null;
	}	shopinfoBean.roleId = jQuery('#roleIdEditor').val();
	
	return shopinfoBean;
};

var initShopInfoPage = function(){
	
	jQuery("#registerTimeEditor").ligerDateEditor({
		format:'yyyy-MM-dd hh:mm',
		showTime:true,
	});
	jQuery('#ligerState').ligerComboBox({
		data:userStateRenderData,
		valueField:'value',
		textField:'text',
		initValue:userStateRenderData[0].value,
		valueFieldID:'stateEditor'
	});
	jQuery('#LigerRoleId').ligerComboBox({
		data:rolesJson,
		valueField:'id',
		textField:'name',
		initValue:rolesJson[0].id,
		valueFieldID:'roleIdEditor'
	});
};

var bindShopInfoUpdateButtom = function(){
	jQuery('#updateEdit').unbind('click').click(function(){
		var shopinfoBean = getShopInfoBeanFromOpenPage();
		if(null != shopinfoBean){
			doSaveShopInfos([shopinfoBean]);
		}
	});
};
var bindShopInfoResetButtom = function(){
	jQuery('#resetEdit').unbind('click').click(function(){
		if(!initShopInfoBean){
			jQuery("#nameEditor").val('');
			jQuery("#masterNameEditor").val('');
			jQuery("#masterCardEditor").val('');
			jQuery("#emailEditor").val('');
			jQuery("#phoneEditor").val('');
			jQuery("#addressEditor").val('');
			jQuery("#registerTimeEditor").val('');
			jQuery("#stateEditor").val('');
			jQuery("#passwdEditor").val('');
			jQuery("#roleIdEditor").val('');
		}else{
			if(!initShopInfoBean.name){
				jQuery("#nameEditor").val('');
			}else{
				jQuery("#nameEditor").val(initShopInfoBean.name);
			}
			if(!initShopInfoBean.masterName){
				jQuery("#masterNameEditor").val('');
			}else{
				jQuery("#masterNameEditor").val(initShopInfoBean.masterName);
			}
			if(!initShopInfoBean.masterCard){
				jQuery("#masterCardEditor").val('');
			}else{
				jQuery("#masterCardEditor").val(initShopInfoBean.masterCard);
			}
			if(!initShopInfoBean.email){
				jQuery("#emailEditor").val('');
			}else{
				jQuery("#emailEditor").val(initShopInfoBean.email);
			}
			if(!initShopInfoBean.phone){
				jQuery("#phoneEditor").val('');
			}else{
				jQuery("#phoneEditor").val(initShopInfoBean.phone);
			}
			if(!initShopInfoBean.address){
				jQuery("#addressEditor").val('');
			}else{
				jQuery("#addressEditor").val(initShopInfoBean.address);
			}
			if(!initShopInfoBean.registerTime){
				jQuery("#registerTimeEditor").val('');
			}else{
				var temp = new Date(initShopInfoBean.registerTime);
				jQuery("#registerTimeEditor").val(temp.formatLiger());
			}
			if(!initShopInfoBean.state){
				jQuery("#stateEditor").val('');
			}else{
				jQuery("#stateEditor").val(initShopInfoBean.state);
			}
			if(!initShopInfoBean.passwd){
				jQuery("#passwdEditor").val('');
			}else{
				jQuery("#passwdEditor").val(initShopInfoBean.passwd);
			}
			if(!initShopInfoBean.roleId){
				jQuery("#roleIdEditor").val('');
			}else{
				jQuery("#roleIdEditor").val(initShopInfoBean.roleId);
			}
		}
	});
};



jQuery(function(){
	initShopInfoPage();
	bindShopInfoUpdateButtom();
	bindShopInfoResetButtom();
});